﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Base.Entity;
using T.FAS.DataModel.Excel.Service;
using T.FAS.Runtime.SGSPI;
using T.FAS.Runtime.SPI;

namespace T.FAS.Runtime.SGPlugin
{
    public class ExportTaskService: IExportTaskService
    {
        readonly ExportTaskManager exportTaskManager = new ExportTaskManager();
        /// <summary>
        /// 导出数据
        /// </summary>
        /// <param name="exportParam"></param>
        /// <param name="parameters"></param>
        /// <param name="exportDefs"></param>
        public ExportTask ExportData(ExportParam exportParam, List<ExportParameter> parameters, List<ExportDef> exportDefs)
        {
            if (exportParam == null)
                throw new FasException(ExcelConstCode.InValidParam, "ExportTaskService.ExportData.exportParam");
            if (string.IsNullOrEmpty(exportParam.MetaDataID))
                throw new FasException(ExcelConstCode.InValidParam, "ExportTaskService.ExportData.exportParam.MetaDataID");
            if (exportDefs == null)
                throw new FasException(ExcelConstCode.InValidParam, "ExportTaskService.ExportData.exportDefs");
            return exportTaskManager.ExportData(exportParam, parameters, exportDefs);
        }
        /// <summary>
        /// 导出DQ
        /// </summary>
        /// <param name="dataQueryID"></param>
        /// <param name="parameters"></param>
        /// <param name="exportDefs"></param>
        /// <param name="exportType"></param>
        public ExportTask ExportDataQuery(string dataQueryID, List<ExportParameter> parameters, List<ExportDef> exportDefs, int exportType, int type)
        {
            if (string.IsNullOrEmpty(dataQueryID))
                throw new FasException(ExcelConstCode.InValidParam, "ExportTaskService.ExportDataQuery.dataQueryID");
            if (exportDefs == null)
                throw new FasException(ExcelConstCode.InValidParam, "ExportTaskService.ExportData.exportDefs");
            return exportTaskManager.ExportDataQuery(dataQueryID, parameters, exportDefs, exportType, type);
        }
        /// <summary>
        /// 查询导出任务列表
        /// </summary>
        /// <param name="dataQueryID"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public Dictionary<string, object> GetExportTaskList(string dataQueryID, Dictionary<string, string> filter)
        {
            if (string.IsNullOrEmpty(dataQueryID))
                throw new FasException(ExcelConstCode.InValidParam, "ImportTaskService.GetExportTaskList.dataQueryID");
            return exportTaskManager.GetExportTaskList(dataQueryID,filter);
        }
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public Dictionary<string, string> DeleteExportTask(string taskID)
        {
            if (string.IsNullOrEmpty(taskID))
                throw new FasException(ExcelConstCode.InValidParam, "ImportTaskService.DeleteExportTask.taskID");
            return exportTaskManager.DeleteExportTask(taskID);
        }
        /// <summary>
        /// 清空任务
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> ClearExportTask(string metaDataID)
        {
            if (string.IsNullOrEmpty(metaDataID))
                throw new FasException(ExcelConstCode.InValidParam, "ImportTaskService.ClearExportTask.metaDataID");
            return exportTaskManager.ClearExportTask(metaDataID);
        }
    }
}
